#include<bits/stdc++.h>
#define ONLINE_JUDGE
#define ll long long
#define ull unsigned long long
using namespace std;

const ll N = 2e5 + 10, INF = 0x3f3f3f3f;

ll n, k;
ll a[N], f[N][70];

void solve()
{
    cin >> n >> k;
    for (ll i = 1;i <= n;i++) cin >> f[i][0];
    for (ll i = 1;i <= n;i++) cin >> a[i];

    ll p = log2(k);
    for (ll j = 1;j <= p;j++)
        for (ll i = 1;i <= n;i++)
            f[i][j] = f[f[i][j - 1]][j - 1];

    for (ll i = 1;i <= n;i++) {
        ll cur = i, len = k, cnt = 0;
        while (len) {
            if (len & 1) cur = f[cur][cnt];
            len >>= 1;
            cnt++;
        }
        cout << a[cur] << ' ';
    }

}

signed main()
{
    // ios::sync_with_stdio(0);
    // cin.tie(0);cout.tie(0);
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    ll T = 1;
    //cin>>T;
    for (ll i = 1;i <= T;i++) {
        solve();
    }
}